package ys.ewp.facade;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import ys.ewp.dto.DepartmentDto;
import ys.ewp.po.Department;
import ys.ewp.service.DepartmentService;

@Component
public class DepartmentFacade {
	
	@Resource(name="departmentService")
	private DepartmentService departmentService;
	
	/**
	 * @功能 创建部门
	 * @param depDto
	 * @return 部门列表
	 */
	public List<DepartmentDto> createDepartment(DepartmentDto depDto){
		Department dep = DepartmentDto.getPoByDto(depDto);
		departmentService.save(dep);
		return getDepartmentList();
	}
	
	/**
	 * @功能 获取所有部门信息
	 * @return
	 */
	public List<DepartmentDto> getDepartmentList(){
		List<DepartmentDto> depList = this.getDtoListByPoList(departmentService.getList());
		return depList;
	}
	
	/**
	 * 	@功能 根据PO列表获取DTO列表
	 * @param notList 
	 * @return 
	 */
	private List<DepartmentDto> getDtoListByPoList(List<Department> depList){
		
		if(depList == null || depList.isEmpty()){
			return Collections.emptyList();
		}
		List<DepartmentDto> depDtoList = new ArrayList<DepartmentDto>();
		for(Department dep : depList){
			DepartmentDto depDto = null;
			depDto = DepartmentDto.getDtoByPo(dep);
			
			depDtoList.add(depDto);
		}
		return depDtoList;
	}
	
	
}
